﻿using System;  
using UnityEditor;
using UnityEngine;

namespace XFGameFramework.EquipmentSystem
{
    [Serializable]
    public class IconInfo 
    {
        /// <summary>
        /// 图标所在的资源模块名称
        /// </summary>
        [Tooltip("图标所在的资源模块名称")]
        public string projectName;

        /// <summary>
        /// 图标名称
        /// </summary>
        [Tooltip("图标名称")]
        public string iconName;
    }

    public enum EquipmentType 
    {
        /// <summary>
        /// 预制体资源
        /// </summary>
        [Tooltip("预制体资源")]
        Asset,
        /// <summary>
        /// 脚本
        /// </summary>
        [Tooltip("脚本")]
        Script 
    }

    /// <summary>
    /// 装备配置基础数据
    /// </summary> 
    public class EquipmentConfigData : ScriptableObject
    {
        /// <summary>
        /// 当前数据所在的配表
        /// </summary>
        [Tooltip("当前数据所在的配表")]
        [Header("当前数据所在的配表")]
#if UNITY_EDITOR
        [CustomEquipmentConfigDataParentGUI]
#endif
        [ExcelSystem.ExcelIgnore]
        public EquipmentsConfig parent;

        /// <summary>
        /// 装备ID(唯一标识,不可重复)
        /// </summary>
        [Tooltip("装备ID(唯一标识,不可重复)")]
        [Header("装备ID(唯一标识,不可重复)")]
#if UNITY_EDITOR
        [CustomEquipmentConfigDataIDGUI]
#endif
        public int id;

        /// <summary>
        /// 装备名称
        /// </summary>
        [Tooltip("装备名称")]
        [Header("装备名称")]
        public string equipment_name;


        /// <summary>
        /// 装备图标
        /// </summary>
        [Tooltip("装备图标")]
        [Header("装备图标")]
#if UNITY_EDITOR
        [CustomEquipmentConfigDataIconGUI]
#endif
        public IconInfo icon;

        /// <summary>
        /// 装备描述
        /// </summary>
        [Tooltip("装备描述")]
        [Header("装备描述")] 
        [TextArea(3,8)]
        public string description;

        /// <summary>
        /// 装备类型
        /// </summary>
        [Tooltip("装备类型")]
        [Header("装备类型")]
        public EquipmentType equipmentType;

        /// <summary>
        /// 类型全名称(含命名空间) 
        /// </summary>
        [Tooltip("类型全名称(含命名空间) ")]
        [Header("类型全名称(含命名空间) ")]
#if UNITY_EDITOR
        [CustomEquipmentConfigDataClassGUI]
#endif
        public string equipment_class_full_name;

        /// <summary>
        /// 类文件guid
        /// </summary>
        [Tooltip("类文件guid ")]
        [Header("类文件guid ")]
        [HideInInspector]
        public string equipment_class_guid;

        /// <summary>
        /// 装备资源模块名称
        /// </summary>
        [Tooltip("装备资源模块名称 ")] 
        [Header("装备资源模块名称 ")]
#if UNITY_EDITOR
        [CustomEquipmentConfigDataProjectNameGUI]
#endif
        public string projectName;

        /// <summary>
        /// 装备资源名称
        /// </summary>
        [Tooltip("装备资源名称 ")]
        [Header("装备资源名称 ")]
#if UNITY_EDITOR
        [CustomEquipmentConfigDataAssetNameGUI]
#endif
        public string assetName;

#if UNITY_EDITOR

        public void Rename() 
        {
            string asset_path = AssetDatabase.GetAssetPath(this);

            string current_name = AssetNameTools.GetName(id.ToString(), System.IO.Path.GetDirectoryName(asset_path));

            AssetDatabase.RenameAsset(asset_path, current_name);

            AssetDatabase.Refresh();
        }

#endif

    }
}
